//
//  FxGlobal.m
//  sp
//
//  Created by 陶秋安 on 16/1/29.
//  Copyright © 2016年 孙智慧. All rights reserved.
//



#import "FxGlobal.h"
#import "FxFileUtility.h"
#import "MiPush.h"

@implementation FxGlobal
#pragma mark - 缓存路径


+ (FxGlobal *)global
{
    static FxGlobal *s_global = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        s_global = [[FxGlobal alloc] init];
    });
    
    return s_global;
}

- (id)init
{
    self = [super init];
    if (self) {
        self.push = [[MiPush alloc] init];
    }
    
    return self;
}

+ (NSString *)getRootPath
{
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:RootPath];
    
    [FxFileUtility createPath:path];
    
    return path;
}

+ (NSString *)getCacheImage:(NSString *)fileName
{
    NSString *path = [NSString stringWithFormat:@"%@/%@", [FxGlobal getRootPath], CacheImagePath];
    
    [FxFileUtility createPath:path];
    
    path = [NSString stringWithFormat:@"%@/%@", path, fileName];
    
    return path;
}

+ (NSString *)getCacheMp3 
{
 
    
    NSString *path = [NSString stringWithFormat:@"%@/%@", [FxGlobal getRootPath], CacheMusicPath];
    
    [FxFileUtility createPath:path];
    
    return path;
}

+ (NSString *)getUserDBFile
{
    NSString *path = [FxGlobal getRootPath];
    
    return [path stringByAppendingPathComponent:NewsDBFile];
}

+ (NSString *)getDownLoad
{
    NSString *path = [NSString stringWithFormat:@"%@/%@", [FxGlobal getRootPath], DownLoadPath];
    
    [FxFileUtility createPath:path];
    
    return path;
}

+ (BOOL)setNotBackUp:(NSString *)filePath
{
    NSError *error = nil;
    NSURL *fileURL = [NSURL fileURLWithPath:filePath];
    NSNumber *attrValue = [NSNumber numberWithBool:YES];
    
    [fileURL setResourceValue:attrValue
                       forKey:NSURLIsExcludedFromBackupKey
                        error:&error];
    if (error!=nil) {
        //BASE_ERROR_FUN([error localizedDescription]);
        return NO;
    }
    
    return YES;
}

+(NSString *)  getServiceUrl:(NSString *)action andFuncName:(NSString *) funcName
{
    if([serviceport isEqualToString:@""])
    {
        NSString *url = [NSString stringWithFormat:@"http://%@/%@/%@/%@",serviceip,servicemain,action,funcName];
        return url;
    }
    else
    {
        NSString *url = [NSString stringWithFormat:@"http://%@:%@/%@/%@/%@",serviceip,serviceport, servicemain,action,funcName];
        return url;
    }
}

@end
